#pragma once

#ifndef INPUTHANDLER_H
#define INPUTHANDLER_H

#include <Windows.h>
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>

#pragma comment(lib, "dinput8.lib")
#pragma comment(lib, "dxguid.lib")

class InputHandler
{
private:
	// handle to window using directx
	HWND hWnd;
	// DirectInput object
	IDirectInput8* dInput;
	// mouse device
	IDirectInputDevice8* mouse;
	// keyboard device
	IDirectInputDevice8* keyboard;
	// current keyboard state
	unsigned char keyboardState[256];
	// keyboard state from last frame
	unsigned char previousKeyboardState[256];
	// current mouse state
	DIMOUSESTATE2 mouseState;
	// previous mouse state
	DIMOUSESTATE2 previousMouseState;
	// current mouse position
	POINT mousePosition;
	// previous mouse position
	POINT previousMousePosition;
public:
	// constructor
	InputHandler(HINSTANCE hInstance, HWND hWnd);
	// destructor 
	virtual ~InputHandler();
	// updates state value in InputHandler
	void poll();
	// check if key is down
	bool isKeyDown(unsigned char key) const;
	// check if key was down
	bool wasKeyDown(unsigned char key) const;
	// gets current mouse state
	DIMOUSESTATE2 getCurrentMouse() const { return mouseState; }
	// gets previous mouse state
	DIMOUSESTATE2 getPreviousMouse() const { return previousMouseState; }
	// gets current mouse position
	POINT getCurrentMousePos() const { return mousePosition; }
	// gets previous mouse position
	POINT getPreviousMousePos() const { return previousMousePosition; }
};

#endif